<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot>
      </slot>
    </div>
  </div>
</template>
<script>
import BScroll from "better-scroll"
export default {
  props:{
    probeType:{
      type:Number,
      default:0
    },
    pullUpLoad:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      scroll:null
    }
  },
  mounted(){
    //创建BScroll对象
    this.scroll = new BScroll(this.$refs.wrapper,{
      click: true,//点击事件
      probeType:this.probeType ,//监听滚动位置
      pullUpLoad:this.pullUpLoad //下拉刷新
    })
    //监听滚动位置
    this.scroll.on("scroll",(position)=>{
    //发射出去监听到的位置
      this.$emit('scroll',position)
    })

    //监听scroll滚动到底部
    this.scroll.on("pullingUp",()=>{
      this.$emit("pullingUp")
    })
  },

  methods: {
    //回到顶部
    scrollTo(x, y, time){
      this.scroll && this.scroll.scrollTo(x, y,time)
    },
    //可多次下拉回调
    finishPullUp(){
      this.scroll.finishPullUp()
    },
    //重新计算可滚动内容
    refresh(){
     this.scroll && this.scroll.refresh()
    }
  },
  
}
</script>
<style scoped>
</style>
